<template>
    <div class="p20">
            <!-- search -->
            <el-form :inline="true">
                <el-form-item label="类型">
                    <el-select v-model="search.type" @change="getListData" placeholder="请选择">
                        <el-option label="彩金" value="game_coupon"> </el-option>
                        <el-option label="公司" value="game_company"> </el-option>
                        <el-option label="小猴说事" value="posts"> </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="时间">
                    <el-date-picker v-model="search.timeRange" @change="transformTimeRange" type="datetimerange" placeholder="选择时间范围"> </el-date-picker>
                </el-form-item>
            </el-form>

            <!-- 列表 -->
            <div @click="link(item)" v-for="item in listData" class="ui-border-bottom flex pb15 pt15 cursor-pointer">
                <ui-img :url="item.thumb || item.avatar" size="50px" class="mr10"></ui-img>
                <div class="flex-1">
                    <div class="f-color-grey f10 mb10">{{item.createtime}}</div>
                    <span class="mr50">
                        <i class="f-color-grey">[{{item.catename}}]</i>
                        <i>{{item.title}}</i>
                    </span>
                </div>
            </div>

            <!-- 分页 -->
            <div class="text-center mt15">
                <el-pagination
                @current-change="getListData"
                :current-page.sync="pageCurrent"
                :page-size="pageSize"
                layout="prev, pager, next, jumper"
                :total="pageTotal">
                </el-pagination>
            </div>
    </div>
</template>
<script>
    export default {
        data(){
            return {
                search:{
                    type:'',
                    timeRange:[],
                    begin_time:'',
                    end_time:''
                },
                pageCurrent:0,
                pageSize:10,
                pageTotal: 0,
                listData:[]
            }
        },
        methods:{
            getListData(){
                this.$http.get('index.php?g=home&m=Users&a=favorites', {
                    params:Object.assign({},this.search, {
                        page_size:this.pageSize,
                        page_no:this.pageCurrent
                    })
                })
                .then(({data})=>{
                    console.log('收藏列表',data)
                    if (data.code===1) {
                        // 优惠券点赞+评论点赞
                        this.listData = data.data
                        this.pageTotal = parseInt(data.total)
                    }
                })
            },
            link(item){
                if (!item.object_id) {
                    return
                }
                this.$router.push({
                    name:item.catename==="小猴说事"? '文章详情':'彩金详情',
                    query:{id:item.object_id}
                })
            },
            transformTimeRange(v){
                if (v) {
                    let str = v.split(' - ')
                    this.search.begin_time = str[0]
                    this.search.end_time = str[1]

                    this.getListData()
                }
            }
        },
        mounted(){
            this.pageCurrent = 1
        },
    }
</script>